/**
 * 确认现金支付已完成
 */

//引入Q模块
let Q = require('q');
//引入公共函数
let util = require('../../util');

//checkCashPayDone接口入口函数
let index = function(getData, postData, config, _redis, db) {
	let deferred = Q.defer();
	if(postData.orderId) {
		db.select('storeOrder', {
			orderId: postData.orderId,
			userPayed: false
		}).then(function(data) {
			if(data.length == 0) {
				deferred.resolve(1);
			}
			else {
				//商户尚未确认收款
				deferred.reject('-0189');
			}
		}, function() {
			//查询未现金支付订单用户失败
			deferred.reject('-0186');
		});
	}
	else {
		//确认现金支付已完成接口参数不足
		deferred.reject('-0188');
	}
	return deferred.promise;
}

module.exports = {
	index: index
}